﻿using System;
using System.Collections.Generic;
using System.Web;
using BingZi;
using NewLife.Web;
using BingZi.HY.Core;

namespace FrameWork.web.Includes.WebServices
{
    /// <summary>
    /// VerificationHandler1 的摘要说明
    /// </summary>
    public class VerificationHandler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Clear();
            String Vtype = Common.querySQL(WebHelper.GetStringParam(context.Request, "Vtype", ""));
            switch (Vtype)
            {
                case "email":

                    context.Response.Write(ajaxEmailCall());
                    break;
                case "user":

                    context.Response.Write(ajaxUserCall());
                    break;
            }
            context.Response.End();
        }
        private String ajaxUserCall()
        {
            String Vuser = Common.querySQL(WebHelper.GetStringParam(HttpContext.Current.Request, "fieldValue", ""));
            String validateId = WebHelper.GetStringParam(HttpContext.Current.Request, "fieldId", "");
            String validateError = WebHelper.GetStringParam(HttpContext.Current.Request, "extraData", "");
            sys_UserTable userInfo =sys_UserTable.FindByUserName(Vuser);
            if (userInfo != null && userInfo.UserID > 0)
            {
                return "{\"jsonValidateReturn\":[\"" + validateId + "\",\"" + validateError + "\",false]}";
            }
            return "{\"jsonValidateReturn\":[\"" + validateId + "\",\"" + validateError + "\",true]}"; ;
        }

        private String ajaxEmailCall()
        {
            String Vemail = Common.querySQL(WebHelper.GetStringParam(HttpContext.Current.Request, "fieldValue", ""));
            String validateId = WebHelper.GetStringParam(HttpContext.Current.Request, "fieldId", "");
            String validateError = WebHelper.GetStringParam(HttpContext.Current.Request, "extraData", "");
            sys_UserTable userInfo = sys_UserTable.FindByEmail(Vemail);
            if (userInfo != null && userInfo.UserID > 0)
            {
                return "{\"jsonValidateReturn\":[\"" + validateId + "\",\"" + validateError + "\",false]}";
            }
            return "{\"jsonValidateReturn\":[\"" + validateId + "\",\"" + validateError + "\",true]}";
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}